package com.eos.control.action.customer;

import java.util.List;

import com.eos.business.service.SysProductBusinessService;
import com.eos.common.tool.ConstantTool;
import com.eos.common.tool.ObjectUtils;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.SysColour;
import com.eos.orm.mybatis.model.SysUser;

public class UpdateColorAction extends AbstractBaseAction {
	private static final long serialVersionUID = 8337902688280706690L;
	private Integer colorId;
	private String colorName;
	private String oldColorName;

	public void setColorId(Integer colorId) {
		this.colorId = colorId;
	}

	public void setColorName(String colorName) {
		this.colorName = colorName;
	}

	public void setOldColorName(String oldColorName) {
		this.oldColorName = oldColorName;
	}

	@Override
	public String execute() {
		try {
		  if(null == colorId || colorId.longValue() == 0){
				statusCode = "300";
				message = "参数错误,保存失败!";
			}else {
				SysColour color = new SysColour();
				color.setColourName(colorName);
				SysProductBusinessService spbs = new SysProductBusinessService();
				if(!colorName.equals(oldColorName)){
					color.setDealFlag(ConstantTool.DEAL_FALG_OK);
					color.setStatus(ConstantTool.STATUS_OK);
					List<SysColour> colorList = spbs.getSysColorExample(color);
					if(null != colorList && colorList.size() > 0){
						statusCode = "300";
						message = "输入的颜色名称已经存在, 修改失败!";
					}else{
						SysUser user = (SysUser) getSession().getAttribute("SysUser");
						color.setId(colorId);
						color.setUpdateUserId(user.getId()+"");
						color.setModifyTime(ObjectUtils.formatDate(null, "yyyy-MM-dd HH:mm:ss"));
						String exeStatus = spbs.updateSysColorSelective(color);
						if("SUCCESS".equals(exeStatus)){
							statusCode = "200";
							message = "修改颜色信息成功!";
						}else{
							statusCode = "300";
							message = "系统繁忙, 修改颜色信息失败!";
						}
					}
				}else{
					statusCode = "200";
					message = "修改颜色信息成功!";
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			statusCode = "300";
			message = "系统异常, 修改颜色信息失败!";
		}
		return SUCCESS;
	}
}
